﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TKToXML
{
    public class ExportableList
    {
        public string MaDV { get; set; }
        public string MaDVDL { get; set; }
        public string Type { get; set; }
        public DateTime IssueDate { get; set; }
        public string Function { get; set; }
        public string Reference { get; set; }
        public int Status { get; set; }
        public string MaHQ { get; set; }
        public string TenHang { get; set; }
        public string MaPhu { get; set; }
        public string MaHS { get; set; }

        public string TenDV
        {
            get
            {
                using (var context = new ECUSTOMSEntities())
                {
                    var donVi = context.SDONVIs.Where(dv => dv.Ma == MaDV).First();

                    return donVi.Ten_U;
                }
            }
        }
        public string TenDVDL
        {
            get
            {
                using (var context = new ECUSTOMSEntities())
                {
                    var donVi = context.SDONVIs.Where(dv => dv.Ma == MaDVDL).First();

                    return donVi.Ten_U;
                }
            }
        }        

        public string ToXML()
        {
            string result = "<Declaration>";
                result += "<issuer>" + Type + "</issuer>";
                result += "<issue>" + IssueDate.ToString() + "</issue>";//2010-08-17 16:40:00
                result += "<function>" + (int)MessageFuntion.KhaiBao + "</function>"; 
                result += "<reference>" + Reference + "</reference>";
                result += "<status>" + "1" + "</status>";//Status khong dung, luon dat la 1
                result += "<declarationOffice>" + MaHQ +"</declarationOffice>";
             
                result += "<Agent>";
                    result += "<name>" + TenDV + "</name>"; //DHL
                    result += "<identity>" + MaDV + "</identity>";
                    result += "<status>" + Status.ToString() + "</status>";
                result += "</Agent>";

                result += "<Exporter>";
                    result += "<name>" + TenDVDL + "</name>"; //"Intel Products Vietnam Co. Ltd."
                    result += "<identity>" + MaDVDL +"</identity>"; //"0304295429"
                result += "</Exporter>";
  
                result += "<OutgoingGoodsItem>";
                    result += "<Commodity>";
                        result += "<description>" + TenHang +"</description>";//"dien thoai di dong"
                        result += "<identification>" + MaPhu +"</identification>";//"hang1"
                        result += "<tariffClassification>" + MaHS +"</tariffClassification>";//"8542310000"
                        result += "<usage>" + "1" + "</usage>";
                        result += "<type>" + "1" + "</type>";
                    result += "</Commodity>";
                    result += "<GoodsMeasure>";
                        result += "<measureUnit>" + "17" + "</measureUnit>";
                    result += "</GoodsMeasure>";
                result += "</OutgoingGoodsItem>";

            result += "</Declaration>";

            return result;
        }
    }
}
